package org.restbox.controller;

import org.restbox.form.RequestForm;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

/**
 * Controller for the index.
 *
 * @author troig
 */
@Controller
@RequestMapping(value = "/request")
public class RequestController {

   /**
    * Load empty request form
    *
    * @param model Model
    * @return jsp request redirect
    */
   @RequestMapping(value = "/load")
   public String load(Model model) {
      model.addAttribute("requestForm", new RequestForm());
      return "request";
   }

   /**
    * Send the request passed by form
    *
    * @param requestForm Request form
    * @param model       Model Model
    * @return jsp response redirect
    */
   @RequestMapping(value = "/send", method = RequestMethod.POST)
   public String send(@ModelAttribute("requestForm") RequestForm requestForm, Model model) {
      model.addAttribute("message", requestForm.getUrl());
      return "response";
   }
}
